home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / DCLAP 6d / dclap6d / DClap / DFindDlog.cpp < prev    next >
Text File  |  1996-07-05  |  5KB  |  218 lines

  1. // DFindDlog.cpp
  2.  
  3.  
  4. #include <ncbi.h>
  5. #include <dgg.h>
  6. #include <Dvibrant.h>
  7. #include <DControl.h>
  8. #include <DDialogText.h>
  9. #include <DApplication.h>
  10. #include <DMenu.h>
  11. #include <DWindow.h>
  12. #include <DTask.h>
  13. #include <DUtil.h>
  14. #include "DFindDlog.h"
  15.  
  16.  
  17. Boolean DFindDialog::fBackwards= false;
  18. Boolean DFindDialog::fCaseSense= false;
  19. Boolean DFindDialog::fFullWord= false;
  20. char* DFindDialog::fTarget[DFindDialog::kMaxTarg];
  21. char* DFindDialog::fReplace[DFindDialog::kMaxReplace];
  22.  
  23.  
  24. void DFindDialog::FindAgain()
  25. {
  26.     Boolean saveback= fBackwards;
  27.     fBackwards= gKeys->shift(); 
  28.     DoFind();
  29.     fBackwards= saveback;
  30. }
  31.  
  32. Boolean DFindDialog::IsMyAction(DTaskMaster* action) 
  33. {    
  34.     DView* aview= (DView*) action;
  35.  
  36.     switch (action->Id()) {
  37.         case cBackwards : fBackwards= aview->GetStatus(); return true;
  38.         case cCaseSense : fCaseSense= aview->GetStatus(); return true;
  39.         case cFullWord  : fFullWord= aview->GetStatus(); return true;
  40.  
  41.         case findId:
  42.         case replaceId:
  43.         case replaceFindId:
  44.         case replaceAllId:
  45.             switch (action->Id()) {
  46.                 case replaceFindId: 
  47.                     GetReplace(); DoReplace(); 
  48.                     // fall into findId
  49.                 case findId        : 
  50.                     GetFind(); DoFind();     
  51.                     break;
  52.                     
  53.                 case replaceId: 
  54.                     GetReplace(); DoReplace(); 
  55.                     break;
  56.                     
  57.                 case replaceAllId: 
  58.                     GetReplace(); DoReplaceAll(); 
  59.                     break;
  60.                 }
  61.             fModal= false;
  62.             this->Close(); 
  63.             return true;
  64.             
  65.         default:
  66.             return DWindow::IsMyAction(action);    
  67.         }
  68. }
  69.  
  70.  
  71. DFindDialog::DFindDialog() :
  72.   DWindow( 0, gApplication, DWindow::fixed, -10, -10, -50, -20, "Find", kDontFreeOnClose) 
  73.     //fBackwards(false), fCaseSense(false), fFullWord(false)
  74. {
  75.     fFindText= NULL;
  76.     fReplaceText= NULL;
  77. #if 0
  78.     short i;
  79.     for (i=0; i<kMaxTarg; i++) fTarget[i] = NULL;
  80.     for (i=0; i<kMaxReplace; i++) fReplace[i] = NULL;
  81. #endif
  82. }
  83.  
  84. void DFindDialog::Open()
  85. {
  86.     if (!fFindText) BuildDlog();     
  87.     this->Select(); // for motif
  88.     DWindow::Open();
  89. }
  90.  
  91. void DFindDialog::InitFindDialog()
  92. {
  93.     short i;
  94.     fBackwards= false;
  95.     fCaseSense= false;
  96.     fFullWord= false;
  97.     for (i=0; i<kMaxTarg; i++) fTarget[i] = NULL;
  98.     for (i=0; i<kMaxReplace; i++) fReplace[i] = NULL;
  99. }
  100.  
  101. const char* DFindDialog::GetReplace()
  102. {
  103.     if (fReplaceText) {
  104.         char* str= fReplaceText->GetText();
  105.         Boolean gotstr= (str && *str);
  106.         if (gotstr && (!fReplace[0] || StringCmp( str, fReplace[0]) != 0)) {
  107.             MemFree(fReplace[kMaxReplace-1]);
  108.             for (short i=kMaxReplace-1; i>0; i--) fReplace[i] = fReplace[i-1];
  109.             fReplace[0]= str;
  110.             }
  111.         else
  112.             MemFree( str);
  113.         return fReplace[0];
  114.         }
  115.     else return NULL;
  116. }
  117.  
  118. const char* DFindDialog::GetFind()
  119. {
  120.     if (fFindText) {
  121.         char* str= fFindText->GetText();
  122.         Boolean gotstr= (str && *str);
  123.         if (gotstr && (!fTarget[0] || StringCmp( str, fTarget[0]) != 0)) {
  124.             MemFree(fTarget[kMaxTarg-1]);
  125.             for (short i=kMaxTarg-1; i>0; i--) fTarget[i] = fTarget[i-1];
  126.             fTarget[0]= str;
  127.             }
  128.         else
  129.             MemFree( str);
  130.         return fTarget[0];
  131.         }
  132.     else return NULL;
  133. }
  134.     
  135.  
  136. DFindDialog::~DFindDialog()
  137. {
  138. #if 0
  139.     short i;
  140.     for (i=0; i<kMaxTarg; i++) MemFree(fTarget[i]);
  141.     for (i=0; i<kMaxReplace; i++) MemFree(fReplace[i]);
  142. #endif
  143. }
  144.  
  145.  
  146. void DFindDialog::BuildDlog()
  147. {
  148.     DView * super;
  149.     DPrompt* pr;
  150.     DCheckBox* ck;
  151.     DCluster * maincluster;
  152.     DDefaultButton* db;
  153.     DButton* bb;
  154.     char    * target;
  155.     Nlm_PoinT npt;
  156.     
  157.     super= this;
  158.  
  159. #if 0    
  160.         // this cluster messes up location of DEditText....
  161.     maincluster= new DCluster( 0, super, 60, 40, true, NULL); 
  162.     super= maincluster;
  163. #endif
  164.  
  165.     pr= new DPrompt( 0, super, "   Find", 0, 0, Nlm_programFont);             
  166.     super->NextSubviewToRight();
  167.     target= fTarget[0];
  168.     fFindText= new DEditText( 0, super, target, 50, Nlm_programFont); 
  169.     this->SetEditText( fFindText);
  170.  
  171.     super->NextSubviewBelowLeft();
  172.     pr= new DPrompt( 0, super, "Replace", 0, 0, Nlm_programFont);             
  173.     super->NextSubviewToRight();
  174.     target= fReplace[0];
  175.     fReplaceText= new DEditText( 0, super, target, 50, Nlm_programFont); 
  176.  
  177.  
  178.     maincluster= new DCluster( 0, super, 60, 10, true, NULL); 
  179.     super= maincluster;
  180.  
  181.     super->NextSubviewBelowLeft();
  182.     ck= new DCheckBox(cBackwards, super, "Backwards");
  183.     ck->SetStatus(fBackwards);
  184.     super->NextSubviewToRight();
  185.     ck= new DCheckBox(cCaseSense, super, "Case sensitive");
  186.     ck->SetStatus(fCaseSense);
  187.     super->NextSubviewToRight();
  188.     ck= new DCheckBox(cFullWord, super, "Entire word");
  189.     ck->SetStatus(fFullWord);
  190.     //super->NextSubviewToRight();
  191.  
  192.     super= this;
  193.     //super->NextSubviewToRight();
  194.     super->NextSubviewBelowLeft();
  195.  
  196. #if 1
  197.     maincluster= new DCluster( 0, super, 10, 40, true, NULL); 
  198.     super= maincluster;
  199. #endif
  200.  
  201.     bb= new DButton( replaceId, super, "Replace");
  202.     super->NextSubviewToRight();
  203.     bb= new DButton( replaceFindId, super, "Replace & Find");
  204.     super->NextSubviewToRight();
  205.     bb= new DButton( replaceAllId, super, "Replace All");
  206.     super->NextSubviewToRight();
  207.      super->GetNextPosition( &npt);
  208.      npt.x += 8;   
  209.      super->SetNextPosition( npt);
  210.     db= new DDefaultButton( findId, super, "Find");
  211.     //db->SetResize( DView::fixed, DView::moveinsuper); 
  212.  
  213.     super = this;
  214. }
  215.     
  216.  
  217.  
  218.